<template>
    <div class="photoinfo-container">
        <!-- 标题区域 -->
        <h3>{{ photoinfo.title }}</h3>
        <p class="subtitle">
            <span>发表时间：{{ photoinfo.add_time | dateFormat }}</span>
            <span>点击：{{ photoinfo.click }}次</span>
        </p>

        <hr>

        <!-- 缩略图区域 -->
        <div class="thumbs">
            <vue-preview :slides="slide1" @close="handleClose"></vue-preview>
        </div>

        <!-- 文字详情区域 -->
        <div class="content" v-html="photoinfo.content"></div>

        <cmt-box :id="id"></cmt-box>
    </div>
</template>

<script>
import comment from '../subcomponents/comment.vue'

export default {
    data() {
        return {
            id: this.$route.params.id,
            photoinfo: {},
            slide1: [], // 缩略图数组
        }
    },
    created() {
        this.getPhotoInfo()
        this.getThumbs()
    },
    methods: {
        getPhotoInfo() {
            this.$http.get('api/getimageInfo/' + this.id).then(result => {
                if (result.body.status === 0) {
                    this.photoinfo = result.body.message[0]
                }
            })
        },
        getThumbs() {
            this.$http.get('api/getthumimages/' + this.id).then(result => {
                if (result.body.status === 0) {
                    result.body.message.forEach(item => {
                        item.h = 400
                        item.w = 600
                        item.msrc = item.src
                    })

                    this.slide1 = result.body.message
                }
            }) 
        },
        handleClose() {
            console.log('close thumbs');
        }
    },
    components: {
        'cmt-box': comment
    }
}
</script>

<style lang="scss">
    .photoinfo-container {
        padding: 5px;

        h3 {
            text-align: center;
            font-size: 15px;
            margin: 15px 0;
            color: blue;
        }

        .subtitle {
            display: flex;
            justify-content: space-between;
        }

        .content {
            font-size: 13px;
            line-height: 30px;
        }

        // 缩略图的默认配置
        // 要去掉 scoped 才能生效
        .my-gallery {
            display: flex;
            flex-wrap: wrap;

            figure {
                width: 30%;
                margin: 5px;

                img {
                    width: 100%;
                }
            }
        }
    }
</style>